<template>
    <div>
        <h1>编辑页面</h1>
        <table>
            <thead>
                <tr>
                    <td>商铺名称</td>
                    <td><input type="text" v-model="data.shoopName"></td>
                </tr>
                <tr>
                    <td>商铺楼层</td>
                    <td>
                        <select v-model="data.louceng">
                            <option value="">请选择</option>
                            <option value="1楼">1楼</option>
                            <option value="2楼">2楼</option>
                            <option value="3楼">3楼</option>
                            <option value="4楼">4楼</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>商铺编号</td>
                    <td><input type="text" v-model="data.bianhao"></td>
                </tr>
                <tr>
                    <td>建筑面积</td>
                    <td><input type="text" v-model="data.jMianji"></td>
                </tr>
                <tr>
                    <td>室内面积</td>
                    <td><input type="text" v-model="data.sMianji"></td>
                </tr>
                <tr>
                    <td>租金</td>
                    <td><input type="text" v-model="data.price"></td>
                </tr>
                <tr>
                    <td>商铺状态</td>
                    <td>
                        <select v-model="data.zid">
                                <option value="0">请选择</option>
                                <option v-for="a in Xiala" :value="a.zid">{{a.zhuantai}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>备注说明</td>
                    <td><textarea v-model="data.beizhu"></textarea></td>
                </tr>
                <tr>
                    <td>业主/租户姓名:</td>
                    <td><input type="text" v-model="data.yzName"></td>
                </tr>
                <tr>
                    <td>联系方式:</td>
                    <td><input type="text" v-model="data.phone"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="修改" class="btn btn-success" @click="UpdateShoo"></td>
                </tr>
            </thead>
        </table>

    </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue'
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter();
const route = useRoute();

const UpdateShoo=()=>{
    if(data.value.shoopName=="")
{
    alert('商铺名称不能为空')
    return;
}
if(data.value.louceng=="")
{
    alert('商铺楼层不能为空')
    return;
}
if(data.value.bianhao=="")
{
    alert('商铺编号不能为空')
    return;
}
if(data.value.jMianji=="")
{
    alert('建筑面积不能为空')
    return;
}
if(data.value.sMianji=="")
{
    alert('室内面积不能为空')
    return;
}
if(data.value.price=="")
{
    alert('租金不能为空')
    return;
}
if(data.value.zid==0)
{
    alert('商铺状态不能为空')
    return;
}
if(data.value.beizhu=="")
{
    alert('备注说明不能为空')
    return;
}
if(data.value.yzName=="")
{
    alert('业主/租户名称不能为空')
    return;
}

if(data.value.phone=="")
{
    alert('联系方式不能为空')
    return;
}
if(data.value.phone.length!=11)
{
    alert('联系方式有误请重新输入!!!!')
    return;
}

    axios.post("/api/Shoop/Update",data.value).then(res=>{
        if(res.data>0)
    {
            alert("修改成功");
            router.push({path:'/'});
    }
    else if(res.data==-1)
    {
            alert("租户手机号重复!!");
            return;
    }
    else{
        alert('修改失败');
        
    }
    })
}
















onMounted(()=>{
    Xialas()
    Show()
})

const data = ref(
    {
  "sid": 2,
  "shoopName": "A101",
  "louceng": "1楼",
  "bianhao": "101",
  "jMianji": "19.00平方米",
  "sMianji": "10.00平方米",
  "price": "2399.00/平",
  "zid": 2,
  "beizhu": "阳光房",
  "times": null,
  "yzName": "张三",
  "phone": "15738179297",
  "luoji": true,
  "deleteTimes": null
}
)

const Show=()=>{
    axios.get("/api/Shoop/ChaQuan",{params:{id:route.query.id}}).then(res=>{
        data.value=res.data;    
    })
}










const Xiala=ref([
{
    "zid": 1,
    "zhuantai": "空闲"
  }
])
const Xialas=()=>{
    axios.get("/api/Shoop/ChaZT").then(res=>{
        Xiala.value=res.data;
    })
}

</script>

<style scoped>

</style>